package com.voice.call.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;



//拦截器
@Component
public class AccessIpInterceptor extends HandlerInterceptorAdapter{
	
	//private static Logger log = LoggerFactory.getLogger(AccessIpInterceptor.class);

	//在请求处理之前进行调用（Controller方法调用之前）
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
	              throws Exception {
		
		//请求前实现拦截，如：ip白明单，黑明单功能
		
		//log.info("未配置黑名白，不受访问限制");
		
		return true;
		
	}
	
	/***
	//请求处理之后进行调用，但是在视图被渲染之前（Controller方法调用之后）
	  @Override
	  public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
	    String ip = IPAddressUtil.getClientIpAddress(httpServletRequest);
	    List<BlackList> blackLists = blackListDao.findByIp(ip);
	    if (blackLists == null || blackLists.size() == 0){
	      urlHandle(httpServletRequest, 5000, 10);
	    } else {
	      //强制控制跳转
	      modelAndView.setViewName("/errorpage/error.html");
	    }
	  }
	  ***/
}
